package com.yjhb.android.sbz.activity;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.borjabravo.readmoretextview.ReadMoreTextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.FailDetail;
import com.jojo.android.zxlib.base.mvp.BasePresenter;
import com.jojo.android.zxlib.tool.ZxLogTool;
import com.jojo.android.zxlib.view.CircleImageView;
import com.jojo.android.zxlib.view.nine.ItemImageClickListener;
import com.jojo.android.zxlib.view.nine.NineGridImageView;
import com.jojo.android.zxlib.view.nine.NineGridImageViewAdapter;
import com.jojo.android.zxlib.view.preview.PreviewBuilder;
import com.jojo.android.zxlib.view.preview.enitity.IPreviewInfo;
import com.jojo.android.zxlib.view.preview.util.PreviewUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建者 zx
 * 创建时间 2021/1/25 17:39
 */
public class NoPassDetailActivity extends BaseActivity implements ItemImageClickListener {
    private final String TAG = "NoPassDetailActivity";
    @BindView(R.id.back)
    FrameLayout back;
    @BindView(R.id.title_layout)
    RelativeLayout titleLayout;
    @BindView(R.id.head1_iv)
    CircleImageView head1Iv;
    @BindView(R.id.info1_tv)
    TextView info1Tv;
    @BindView(R.id.content1_tv)
    ReadMoreTextView content1Tv;
    @BindView(R.id.nineGridImageView1)
    NineGridImageView nineGridImageView1;
    @BindView(R.id.layout1)
    LinearLayout layout1;

    NineGridImageViewAdapter<String> adapter1;
    FailDetail failDetail;

    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_no_pass_details;
    }

    @Override
    protected void initUI() {
        content1Tv.setTrimCollapsedText("展开");
        content1Tv.setTrimExpandedText("收起");
        nineGridImageView1.setAdapter(adapter1 = new NineGridImageViewAdapter<String>() {
            @Override
            protected void onDisplayImage(Context context, ImageView imageView, String o) {
                Glide.with(context).load(o)
                        .apply(new RequestOptions().placeholder(com.jojo.android.zxlib.R.drawable.xui_ic_default_img))
                        .into(imageView);
            }
        });
        nineGridImageView1.setMaxSize(9);
        nineGridImageView1.setShowStyle(0);

    }

    @Override
    protected void initData() {
        failDetail = (FailDetail) getIntent().getSerializableExtra("failDetail");
        try {
            if (!TextUtils.isEmpty(failDetail.getRejectReason())) {
                List<String> url = JSON.parseArray(failDetail.getRejectReasonImg(), String.class);
                content1Tv.setText("" + failDetail.getRejectReason());
                nineGridImageView1.setImagesData(url);
            } else {
                layout1.setVisibility(View.GONE);
            }

        } catch (Exception e) {
            ZxLogTool.err(e);
        }
    }

    @Override
    protected void regEvent() {
        nineGridImageView1.setItemImageClickListener(this);
    }


    @OnClick(R.id.back)
    void back() {
        finish();
    }

    @Override
    public void onItemImageClick(ImageView imageView, int index, List list) {
        List<IPreviewInfo> infos = PreviewUtil.ImagesToPreviewInfo(list, imageView);
        PreviewBuilder.from(this)
                .setCurrentIndex(index)
                .setImgs(infos)
                .setDrag(false)
                .start();
    }
}
